FIX enforce VeriFactu isolation across MultiCompany entities - #34
Open
braito4 wants to merge 10 commits into
Open
FIX enforce VeriFactu isolation across MultiCompany entities#34braito4 wants to merge 10 commits into
braito4 wants to merge 10 commits into
Conversation
Author
|
Compatibility validation completed:
The MySQL validation found an existing invalid invoice column ( |
braito4
force-pushed
the
fix/multicompany-entity-isolation
branch
from
July 27, 2026 13:45
6bbf668 to
072eba1
Compare
Author
|
The unrelated |
Author
|
Added dynamic AEAT Multi-OT indicators:
Validated in the two active local entities; both report Multi-OT support and active multi-taxpayer use. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes VeriFactu data, fiscal chains, configuration, and AEAT operations strictly entity-specific when Dolibarr MultiCompany is enabled.
It also prevents VeriFactu from operating with MultiCompany sharing settings that would break the legal separation between taxpayers.
Changes
Strict entity isolation
Fiscal queries use strict equality:
They do not rely on
getEntity('invoice'), because that function may include entities shared by MultiCompany.MultiCompany sharing safeguards
VeriFactu requires the following resources to remain independent:
The new
isEntitySharingAllowed()check detects both directions:Stored sharing options are ignored when the corresponding MultiCompany sharing feature is disabled.
The aggregate
isVerifactuEntityIsolated()check is applied:BILL_VALIDATEeventRechecking during validation covers sharing changes made after activation, entities created from templates, API operations, imports, TakePOS flows, and mass validation.
Validation is also rejected when the invoice belongs to an entity different from the active entity.
Taxpayer identity and certificate isolation
Each VeriFactu-enabled entity must represent a different taxpayer.
The taxpayer NIF is treated as the primary and mandatory cross-entity identity boundary. It is checked before configuration is saved, during module activation, during invoice validation, and before any AEAT submission/query.
The module now:
VERIFACTU_HOLDER_NIFagainst all other VeriFactu-enabled entitiesVERIFACTU_CERTIFICATE_FINGERPRINT_SHA256constantCertificate files, passphrases, schemas, configuration constants, and output directories remain stored under the current entity context.
These checks are neutral when MultiCompany is not enabled, so standalone VeriFactu behavior is unchanged.
AEAT Multi-OT indicators
Enabling MultiCompany alone no longer implies
TipoUsoPosibleMultiOT=S.Both indicators are enabled only when more than one active MultiCompany entity has VeriFactu enabled:
The installation number remains unique per entity.
Defense in depth
The implementation uses three complementary safeguards:
This means an incompatible sharing configuration, duplicated taxpayer identity, or reused certificate cannot enter the AEAT workflow even if introduced after module activation.
Tests and validation
git diff --checkScope
This PR does not modify the external MultiCompany module. VeriFactu enforces isolation at activation and invoice validation time while retaining strict entity filtering at runtime.
A future generic Dolibarr core sharing API could allow MultiCompany to disable incompatible options directly in its administration interface, but it is not required for the fiscal isolation provided by this PR.
General taxpayer-identity immutability, certificate validity/permissions, and OpenSSL command hardening have been separated into PR #41.